//编写学生的数据服务
const StudentModel = require('../db/models/student');

class StudentService {
  async addStudentData(data){

    const sid = data.sid;
    //查询数据seq 中的findOne的方法
    const result = await StudentModel.findOne({
        where: { sid }
    })
    
    if(result) {
        return await StudentModel.update(data, {
          where: { sid }
        })
    }else {
         //create方法创建表数据seq
         return await StudentModel.create(data)
    }
     
    }

  async getStudentData () {
      return await StudentModel.findAll({
        attributes: {
          exclude: ['studentImg']
        }
      })
  }
  async changeStudentStatus (id, status) {
     const res= await StudentModel.update({ status }, {
      where: { id }
    });
     return res[0]
  }
}

module.exports = new StudentService();